package cLog

import "github.com/sirupsen/logrus"

type LogDriver string
type RotationType string
type LogFormat string

const (
	LogConfigName = "LogConf"

	LOG_DRIVER_STDOUT LogDriver = "stdout"
	LOG_DRIVER_FILE   LogDriver = "file"
	LOG_DRIVER_LOKI   LogDriver = "loki"

	LOG_FORMAT_JSON LogFormat = "json"
	LOG_FORMAT_TEXT LogFormat = "text"

	ROTATION_TYPE_MINUTE RotationType = "minute"
	ROTATION_TYPE_HOUR   RotationType = "hour"
	ROTATION_TYPE_DAY    RotationType = "day"
	ROTATION_TYPE_MONTH  RotationType = "month"
	ROTATION_TYPE_YEAR   RotationType = "year"

	rotation_formatter_minute = "%Y%m%d%H%M"
	rotation_formatter_hour   = "%Y%m%d%H"
	rotation_formatter_day    = "%Y%m%d"
	rotation_formatter_month  = "%Y%m"
	rotation_formatter_year   = "%Y"

	LOG_FIELD_LEVEL    string = "level"
	LOG_FIELD_PARAMS   string = "params"
	LOG_FIELD_MESSAGE  string = "message"
	LOG_FIELD_DATETIME string = "datetime"
	LOG_FIELD_REPORTER string = "reporter"
)

const (
	PanicLevel logrus.Level = iota
	FatalLevel
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

var caller_skip = 2
var build_path = ""

type LogConf struct {
	Level      logrus.Level    `json:"level"`
	Drivers    []LogDriver     `json:"drivers"`
	WithFields map[string]any  `json:"with_fields"`
	Excludes   []string        `json:"excludes"`
	Clients    LogConf_Clients `json:"clients"`
}

type LogConf_Clients struct {
	File   FileHook   `json:"file"`
	Loki   LokiHook   `json:"loki"`
	Stdout StdoutHook `json:"stdout"`
}

func (i *LogConf) ConfigName() string {
	return LogConfigName
}

var log_config = &LogConf{
	Level:      TraceLevel,
	Drivers:    []LogDriver{LOG_DRIVER_STDOUT},
	WithFields: make(map[string]any),
	Excludes:   make([]string, 0),
	Clients: LogConf_Clients{
		Stdout: StdoutHook{
			Format:   LOG_FORMAT_TEXT,
			Colorful: true,
		},
	},
}
